<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<link href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
		<script src="js/jquery.min.js"></script>
		<script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
		<style>
			td{width: 20%;}
		</style>
	</head>
	<body>
		<input type="text" name="mark" id="mark" value=""  placeholder="输入价格总分"/>
		<input type="text" name="xishu" id="xishu" value=""  placeholder="输入扣分系数"/>
		<select name="">
			<option value="" disabled="">请选择</option>
			<option value="否">否</option>
			<option value="是">是</option>
		</select>
		<div class="pianli" style="display: none;">
			<input type="text" class="fa"/><input type="text" class="fb"/>
		</div>
		<table>
			<tr>
				<th>报价</th>
				<th>平均值</th>
				<th>扣分数</th>
				<th>最终得分</th>
				<th>备注(有无偏离值)</th>
			</tr>
			<tr>
				<td><input type="text" class="baojia"/></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td><input type="text" class="baojia"/></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td><input type="text" class="baojia"/></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
			<tr>
				<td><input type="text" class="baojia"/></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
			</tr>
		</table>
		
		<script>
			var mark = 0;
			var Aavg = 0,del = 0;
			var sel  = '否';
			var arr= [],n=0;
			
			function getSel(){
				sel = $('select').val();
				switch (sel){
					case "是":
						$('.pianli').show();
						break;
					default:
						$('.pianli').hide();
						break;
				}
			}
			$('select').change(function(){
				getSel();
			})
			function toSort(){
				$('.baojia').each(function(i){
					
					arr[i] = $(this).val();
					arr.sort(sortNumber);
				})
			}
			
			function sortNumber(a,b)
			{
			return b - a
			}
			
			function sum(a){
				var sum=0;
				for(var i=0;i<a.length;i++){
				　　　　　　sum = sum+ Number(a[i]);
				　　　　}
				//console.log(sum)
				return sum;
			};
			$('.baojia').keyup(function(){
				toCal();
				
			})
			
			$('select').change(function(){
				toCal();
			})
			
			
			//计算扣分数
			function kou(baojia){
				//console.log(baojia)
				var xishu = parseFloat($('#xishhu').val());
				if(mark==0||mark==null){console.log('请输入计算总分');del = 0}
				else{
					del = Math.abs(parseFloat(baojia) - parseFloat(Aavg)) *100 * parseFloat(xishu) /  parseFloat(Aavg);
					//console.log(del)
					del = del>0?del:0;
				}
				
				return del.toFixed(2);
			}
			
			//计算最后得分
			function total(baojia){
				return parseFloat(mark)-parseFloat(kou(baojia));
			}
			
			
</script>
		
	</body>
</html>
